home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / cops / cops_104 / perl / rules.pl < prev    next >
Encoding:
Text File  |  1992-03-10  |  2.7 KB  |  130 lines

  1. sub apply_rules {
  2.     local($op, $value, @plan) = @_;
  3.  
  4.     printf("eval($op $value): %s\n", &ascii_plan(@plan)) if $opt_d;
  5.  
  6.     #
  7.     # apply UID attack rules...
  8.     #
  9.     if ($op eq "u") {
  10.     #
  11.     # If we can replace /etc/passwd or /usr/lib/aliases, we can grant 
  12.     # any uid. 
  13.     #
  14.     &addto("r", "/etc/passwd", @plan);
  15.         &addto("r", "/usr/lib/aliases", @plan);
  16.         &addto("r", "/etc/aliases", @plan);
  17.  
  18.     #
  19.     # Check CF's for all usernames with this uid.
  20.     #
  21. uname_loop:
  22.     foreach $uname (split(/ /, $uid2names{$value})) {
  23.         $home = $uname2dir{$uname};
  24.  
  25.         next uname_loop unless $home;
  26.  
  27.         if ($home eq "/") {
  28.         $home = "";
  29.         }
  30.         &addto("r", "$home/.rhosts", @plan);
  31.         &addto("r", "$home/.login", @plan);
  32.         &addto("r", "$home/.logout", @plan);
  33.         &addto("r", "$home/.cshrc", @plan);
  34.         &addto("r", "$home/.profile", @plan);
  35.     }
  36.  
  37.     #
  38.     # Controlling files for root...
  39.     #
  40.     @rootlist = ( 
  41.         "/etc/rc", "/etc/rc.boot", "/etc/rc.single", 
  42.         "/etc/rc.config", "/etc/rc.local", "/usr/lib/crontab",
  43.         "/usr/spool/cron/crontabs",
  44.         );
  45.  
  46.     if ($value eq "0") {
  47.         foreach $file (@rootlist) {
  48.             &addto("r", $file, @plan);
  49.         }
  50.         # Experimental!
  51.         # you can remove this if desired - tjt
  52.         #do "rc.prog";
  53.     }
  54.  
  55.     #
  56.     # Other CFs for non-root folks...
  57.     #
  58.     if ($value ne "0") {
  59.         &addto("r", "/etc/hosts.equiv", @plan);
  60.         if (-s "/etc/hosts.equiv") {
  61.         &addto("r", "/etc/hosts", @plan);
  62.         }
  63.     }
  64.  
  65.     #
  66.     # Plans for attacking GIDs...
  67.     #
  68.     } elsif ($op eq "g") {    # apply gid attack rules
  69.  
  70.     #
  71.     # If we can replace /etc/group we can become any group
  72.     #                  
  73.         &addto("r", "/etc/group", @plan);
  74.  
  75.     #
  76.     # If we can grant any member of a group we can grant that group
  77.     #
  78. member_loop:
  79.     foreach $uname (split(/ /, $gid2members{$value})) {
  80.         if (! defined($uname2uid{$uname})) {
  81.         printf(stderr "group '%s' member '%s' doesn't exist.\n",
  82.             $value,
  83.             $uname);
  84.         next member_loop;
  85.         }
  86.  
  87.         &addto("u", $uname2uid{$uname}, @plan);
  88.     }
  89.  
  90.     #
  91.     # Plans for attacking files...
  92.     #
  93.  
  94.     } elsif ($op eq "r" || $op eq "w") {
  95.  
  96.         ($owner, $group, $other) = &filewriters($value);
  97.  
  98.     &addto("u", $owner, @plan) if ($owner ne "");
  99.     &addto("g", $group, @plan) if ($group ne "");
  100.     &addto("u", "-1", @plan) if ($other);
  101.  
  102.     #
  103.     # If the goal is to replace the file, check the parent directory...
  104.     #
  105.     if ($op eq "r") {
  106.         $parent = $value;
  107.         $parent =~ s#/[^/]*$##;     # strip last / and remaining stuff
  108.  
  109.         if ($parent eq "") {
  110.         $parent = "/";
  111.         }
  112.  
  113.         if ($parent ne $value) {
  114.         &addto("r", $parent, @plan);
  115.         }
  116.     }
  117.  
  118.     } else {            # wow, bad $type of object!
  119.     printf(stderr "kuang: bad op in apply_rules!\n");
  120.     printf(stderr "op '%s' value '%s' plan '%s'\n",
  121.         $op,
  122.         $value,
  123.         &ascii_plan(@plan));
  124.     exit(1);
  125.     }
  126. }
  127.  
  128. 1;
  129.  
  130.